#ifndef __LUNA_VorbisSystem_h__
#define __LUNA_VorbiSSystem_h__

#include "LUNA_Common.h"

#define WIN32_LEAN_AND_MEAN
#include <Windows.h>

//#include "al.h"
#include "Vorbis\vorbisfile.h"

struct OggVorbis_File;

typedef int (*LPOVCLEAR)(OggVorbis_File *vf);
typedef long (*LPOVREAD)(OggVorbis_File *vf,char *buffer,int length,int bigendianp,int word,int sgned,int *bitstream);
typedef ogg_int64_t (*LPOVPCMTOTAL)(OggVorbis_File *vf,int i);
typedef vorbis_info * (*LPOVINFO)(OggVorbis_File *vf,int link);
typedef vorbis_comment * (*LPOVCOMMENT)(OggVorbis_File *vf,int link);
typedef int (*LPOVOPENCALLBACKS)(void *datasource, OggVorbis_File *vf,char *initial, long ibytes, ov_callbacks callbacks);

namespace LUNA
{
	struct LunaExport VorbisSystem
	{
		VorbisSystem();

		HINSTANCE			vorbisDLLHandle;
		LPOVCLEAR			fn_ov_clear;
		LPOVREAD			fn_ov_read;
		LPOVPCMTOTAL		fn_ov_pcm_total;
		LPOVINFO			fn_ov_info;
		LPOVCOMMENT			fn_ov_comment;
		LPOVOPENCALLBACKS	fn_ov_open_callbacks;

		ov_callbacks vorbisCallbacks;

		static size_t read( void *ptr, size_t size, size_t nmemb, void *datasource );
		static int seek( void *datasource, ogg_int64_t offset, int whence );
		static int close( void *datasource );
		static long tell( void *datasource );
		static void swap( short &s1, short &s2 );

		unsigned long decodeOggVorbis( OggVorbis_File *oggVorbisFile,
			char *decodeBuffer, unsigned long bufferSize,
			unsigned long channels );
	};
}

#endif